﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LazyPageLayout.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the LazyPageLayout class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Lidocaine.Data
{
    using System.Collections.Generic;
    using Lidocaine.BusinessObjects;

    /// <summary>
    /// Defines the LazyPageLayout class.
    /// </summary>
    public class LazyPageLayout : BusinessObjects.PageLayout
    {
        /// <summary>
        /// Gets or sets the page's header.
        /// </summary>
        public override BusinessObjects.Template Header
        {
            get
            {
                if (base.Header == null && this.HeaderId != 0)
                {
                    base.Header = Data.Template.Select(this.HeaderId);
                }

                return base.Header;
            }

            set
            {
                base.Header = value;
                if (value != null)
                {
                    this.HeaderId = value.Id;
                }
                else
                {
                    this.HeaderId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the page's footer.
        /// </summary>
        public override BusinessObjects.Template Footer
        {
            get
            {
                if (base.Footer == null && this.FooterId != 0)
                {
                    base.Footer = Data.Template.Select(this.FooterId);
                }

                return base.Footer;
            }

            set
            {
                base.Footer = value;
                if (value != null)
                {
                    this.FooterId = value.Id;
                }
                else
                {
                    this.FooterId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the page's left column.
        /// </summary>
        public override BusinessObjects.Template LeftNav
        {
            get
            {
                if (base.LeftNav == null && this.LeftNavId != 0)
                {
                    base.LeftNav = Data.Template.Select(this.LeftNavId);
                }

                return base.LeftNav;
            }

            set
            {
                base.LeftNav = value;
                if (value != null)
                {
                    this.LeftNavId = value.Id;
                }
                else
                {
                    this.LeftNavId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the page's footer.
        /// </summary>
        public override BusinessObjects.Template TopNav
        {
            get
            {
                if (base.TopNav == null && this.TopNavId != 0)
                {
                    base.TopNav = Data.Template.Select(this.TopNavId);
                }

                return base.TopNav;
            }

            set
            {
                base.TopNav = value;
                if (value != null)
                {
                    this.TopNavId = value.Id;
                }
                else
                {
                    this.TopNavId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the page's style sheet.
        /// </summary>
        public override BusinessObjects.Script Css
        {
            get
            {
                if (base.Css == null && this.CssId != 0)
                {
                    base.Css = Data.Script.Select(this.CssId);
                }

                return base.Css;
            }

            set
            {
                base.Css = value;
                if (value != null)
                {
                    this.CssId = value.Id;
                }
                else
                {
                    this.CssId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the page's javascript.
        /// </summary>
        public override BusinessObjects.Script JavaScript
        {
            get
            {
                if (base.JavaScript == null && this.JavaScriptId != 0)
                {
                    base.JavaScript = Data.Script.Select(this.JavaScriptId);
                }

                return base.JavaScript;
            }

            set
            {
                base.JavaScript = value;
                if (value != null)
                {
                    this.JavaScriptId = value.Id;
                }
                else
                {
                    this.JavaScriptId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the page's content.
        /// </summary>
        public override BusinessObjects.Content Content
        {
            get
            {
                if (base.Content == null && this.ContentId != 0)
                {
                    base.Content = Data.Content.Select(this.ContentId);
                }

                return base.Content;
            }

            set
            {
                base.Content = value;
                if (value != null)
                {
                    this.ContentId = value.Id;
                }
                else
                {
                    this.ContentId = 0;
                }
            }
        }

        /// <summary>
        /// Gets the PageLayout's right column.
        /// </summary>
        public override BusinessObjects.Template RightCol
        {
            get
            {
                if (base.RightCol == null && this.RightColId != 0)
                {
                    base.RightCol = Data.Template.Select(this.RightColId);
                }

                return base.RightCol;
            }

            set
            {
                base.RightCol = value;
                if (value != null)
                {
                    this.RightColId = value.Id;
                }
                else
                {
                    this.RightColId = 0;
                }
            }
        }
    }
}